package com.design.patterns.structuralModel.chainofresponsibility.service.impl;

import com.design.patterns.structuralModel.chainofresponsibility.bean.Request;

import java.util.ArrayList;

public class LimitingMiddleware extends MiddlewareAbstract {

    private final ArrayList<String> cache = new ArrayList<>();

    @Override
    public boolean check(Request request) {
        String ip = (String) request.getHead().get("ip");
        boolean contains = cache.contains(ip);
        if (contains){
            System.out.println("请勿重复请求");
            return false;
        }
        cache.add(ip);
        System.out.println("不限流，放行，IP为" + ip);
        return checkNext(request);
    }
}
